﻿using System;
using System.IO;
using System.Collections.Generic;
using DevExpress.Web.ASPxCallback;

using YhmOA.Model;
using YhmOA.BLL;

namespace YhmOA.Integrated.Car
{
    public partial class OilCardRecordForm : FormPage<Integrated_Car_OilCardRecord>
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                bool isReadOnly = Mode == FormMode.ReadOnly;
                //绑定控件的数据源
                if (!isReadOnly)
                {
                    //刷卡的卡号
                    this.txt_BankNo.DataSource = Integrated_Car_DicBLL.GetBankNoList();
                    this.txt_BankNo.DataBind();
                }
                this.btnCancel.Visible = !isReadOnly;
                this.btnSave.Visible = !isReadOnly;
                base.LoadData(isReadOnly);
            }
        }

        /// <summary>
        /// 编号
        /// </summary>
        private string CardNo
        {
            get
            {
                return Request.QueryString["SN"];
            }
        }

        #region Private Method
        /// <summary>
        /// 保存
        /// </summary>
        /// <returns>保存是否成功</returns>
        private bool save()
        {
            bool isSucceed = false;
            Local = CreateInstance();

            switch (Mode)
            {
                case FormMode.ReadOnly:
                    break;
                case FormMode.Add:
                    Local.CardNo = CardNo;
                    isSucceed = Dal.Add(Local);
                    break;
                case FormMode.Modify:
                    isSucceed = Dal.Update(Local, this._ID);
                    break;
                default:
                    break;
            }

            return isSucceed;
        }

        protected void cbSave_Callback(object source, CallbackEventArgs e)
        {
            ASPxCallback callbackControl = source as ASPxCallback;
            bool isSucceed = this.save();
            callbackControl.JSProperties["cpIsSucceed"] = isSucceed;
        }
        #endregion
    }
}